<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
        $(function (){
            // show();
            $.ajax({
                        url:"dept/listType",
                        type:"get",
                        dataType:"json",
                        success:function (data){
                            alert(data);
                            setList(data);
                        }
                    });
        });
        // function  show(){
        //
        //     $.ajax({
        //         url:"dept/listType",
        //         type:"get",
        //         dataType:"json",
        //         success:function (data){
        //             alert(data);
        //             setList(data);
        //         }
        //     })
        // }
        function setList(data){
            var h ="";
            for (var i in data){
                var d=data[i];
                h+="<option value='"+d.deptno+"'>"+d.dname+"</option>";
            }
            $("#deptno").html(h)
        }
        function findByName(){
            $.ajax({
                url: "emp/findByName",
                type: "post",
                data:"ename="+document.getElementById("ename").value,
                success:function (data){
                    alert(data.ename);
                    $("#dname").attr("value",data.ename);
                    $("input[name='empno']").attr("value",data.empno);
                    $("#deptno").val(data.deptno)
                }

            });
        }
    </script>
</head>

<body>
<div style="padding: 100px 100px 10px;">
    <form class="bs-example bs-example-form" role="form">
        <input type="hidden" name="empno"  >
        <div class="row">
            <div class="col-lg-6">
                <div class="input-group">

                    <input type="text" class="form-control" name="ename" id="ename">
                    <span class="input-group-btn">
						<button class="btn btn-default" type="button" onclick="findByName()" >
							查找
						</button>
					</span>
                </div><!-- /input-group -->
            </div><!-- /.col-lg-6 -->
        </div><!-- /.row -->
    </form>
</div>
<form method="post" action="emp/changeDept">

    <input type="text" id="dname">

<select id="deptno" >




</select>
</form>
</body>
</html>